<!--
 * @name: 
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-08-22 11:09:22
 * @LastEditors: 刘大可
 * @LastEditTime: 2022-09-30 12:20:57
-->
<template>
    <view>
        <cu-custom bgColor="bgmains" :isBack="true">
            <view slot="content">错误日志</view>
        </cu-custom>
        <view class="cu-btn bg-red del" v-if="errorList.length>0" @click="del" >清空</view>
        <block v-for="(item,index) in errorList" :key="index">
            <view class="error margin-lr padding-sm margin-top" v-if="item.url" >
                <view class="url">URL:{{item.url}}</view>
                <!-- <view class="header">header:
                    <block v-for="(header,key) in item.header" :key="key">
                        <view class="row" :class="key">
                            <view class="key">
                                {{key}} :
                            </view>
                            <view class="val">
                                {{header}}
                            </view>
                        </view>
                    </block>
                </view> -->
                <view class="header">请求参数:
                    <block v-for="(header,key) in item.data" :key="key">
                        <view class="row" :class="key">
                            <view class="key">
                                {{key}} :
                            </view>
                            <view class="val">
                                {{header}}
                            </view>
                        </view>
                    </block>
                </view>
                <view class="footer row margin-top-sm">
                    <!-- <view class="btn1 cu-btn round bg-orange" @click="request(item)">一键请求</view> -->
                    <view class="btn1 cu-btn round bg-green margin-lefts" @click="copy(item)">复制参数</view>
                </view>
            </view>
        
        </block>

    </view>
</template>

<script>
// gc_school/pages/webview/index.js
var app = getApp()
import siteInfo from '@/siteinfo.js';
export default {
    data() {
        return {
           errorList:[]
        };
    }
    /**
        http://localhost:8081/h5/index/#/uni_modules/gc-curriculum/pages/index/index?
        wxapp_id=6&s_id=12&shareOpenid=ouMoB5AKEHFnyXecKXC_cj-4AU-k&openid=ouMoB5AKEHFnyXecKXC_cj-4AU-k&wxapp_id=6&s_id=12
     * 
     */
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
      
        this.errorList = uni.getStorageSync('onError')



    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () { },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

        if (this.isLogin == true) {
            uni.reLaunch({
                url: "/gc_school/pages/home/index"
            })
        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () { },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () { },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () { },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () { },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        // return false
        let url = this.url.replace(/openid/g, "shareOpenid")
        console.log(url)
        var path = "/gc_school/pages/webview/index?url=" + encodeURIComponent(url)
        // path=encodeURIComponent(path)
        console.log(path);
        return {
            // title: "vip服务系统",
            path
        }
    },
    methods: {
        request(item){
            const {url,data,header,method}=item
            uni.request({
                url, data,header,method,
                success: ({ data, statusCode, header }) => {},
                fail: (error) => {}
            })
        },
        copy(item){
            uni.setClipboardData({
                data:JSON.stringify(item) ,
                success: (result) => {
                    console.log(result);
                },
                fail: (error) => {
                    console.log(error);
                }
            })
        },
        async del(){
            uni.removeStorageSync('onError')
            this.errorList=[]
            await this.tips.success("清除成功！")
            uni.navigateBack({ delta: 2 })
        }






    }
};
</script>

<style lang="scss">
/* gc_school/pages/webview/index.wxss */
.error{
    width: 690rpx;
    background-color:#fff;
    .header{
        word-break: break-all;
        word-wrap: break-word;
        .row{
            width: 100%;   
            text-indent:1em;
        }
    }
    .Authorization{
        .key{
            width:100rpx;
            flex-shrink:0;
        }
        .val{
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
        }
       
    }
}
.del{
    position:fixed;
    right:30rpx;
    bottom:20vh;
}
</style>
